package com.example.springbootsecurity.controller;


import com.example.springbootsecurity.entity.User;
import com.example.springbootsecurity.service.SysLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@RequestMapping("/user")
@Api(value = "UserApi", description = "用户管理")
@RestController
public class UserController {

    @Autowired
    private SysLoginService loginService;

    @PreAuthorize("@ss.hasPermi('system:menu:query')")
    @ApiOperation(value = "单个查询")
    @GetMapping("/query")
    public User query() {
        return new User().setName("admin");
    }

    @ApiOperation(value = "列表查询")
    @PreAuthorize("@ss.hasPermi('system:menu:list')")
    @GetMapping("/list")
    public Object list() {
        return Arrays.asList(new User().setName("admin"));
    }

    @ApiOperation(value = "列表查询")
    @GetMapping("/delete")
    public Object delete() {
        return "ok";
    }

    @ApiOperation(value = "登录方法")
    @PostMapping("/login")
    public String login(User user) {
        // 生成令牌
        return loginService.login(user.getUsername(), user.getPassword());
    }
}

